<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>添加工程</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    {CSS href="__ADDONSTATIC__css/font.css" /}
    {CSS href="__ADDONSTATIC__css/xadmin.css" /}
    {js href='__ADDONSTATIC__js/jquery-3.2.1.min.js' /}
    {CSS href="__ADDONSTATIC__css/css.css" /}

    {js href='__ADDONSTATIC__js/util.js' /}
    {js href='__ADDONSTATIC__lib/layui/layui.js' /}
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<style>
    .layui-form-label{
        width: 110px;;
    }
    .layui-form-item{
        margin-bottom: 5px;
    }
</style>
<div class="x-body">
    <form class="layui-form">
        <input type="hidden" name="id" value="{$project.id}" class="layui-input">
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>项目名称
            </label>
            <div class="layui-input-inline">
                <span id="name" class="layui-form-label">{$project.name}</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>项目种类
            </label>
            <div class="layui-input-inline">
                <span id="name" class="layui-form-label">{$project.type}</span>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>截止时间
            </label>
            <div class="layui-input-inline">
                <input  id="end_time" name="end_time" required="" value="{$project.end_time}" class="layui-input">
            </div>
        </div>
        {volist name='parts' id='part'}
        <div class="layui-form-item">
            <label class="layui-form-label">
                {$part.name}
            </label>
            <div class="layui-input-inline">
                <select name="{$part.pname}" lay-filter="part" lay-search>
                    <option value=""> 请选择 </option>
                    {volist name='part.members' id='member'}
                    {if condition="$project[$part.pname] == $member.id"}
                    <option value="{$member.id}" selected>{$member.name}</option>
                    {else/}
                    <option value="{$member.id}">{$member.name}</option>
                    {/if}
                    {/volist}
                </select>
            </div>
        </div>
        {/volist}
        <div class="layui-form-item">
            <label for="position" class="layui-form-label">
                坐落位置
            </label>
            <div class="layui-input-inline">
                <input type="text" id="position" name="position"  value="{$project.position}" autocomplete="off" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="position" class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                更新
            </button>
        </div>
    </form>
</div>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#end_time' //指定元素
        });
    });
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form, layer = layui.layer;
        var parts = [];

        //监听提交
        form.on('submit(add)', function (data) {
            data.field.parts = parts;
            console.log(data.field);
            if (data.field.end_time){
                data.field.end_time=new Date(data.field.end_time).getTime()/1000;
            }else{
                data.field.end_time=null;
            }
            ajaxUrl("{:addonUrl('Project/update')}",data.field,function(res){
                console.log(res);
                layer.alert(res.message, {}, function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                    if(res.code == '1'){
                        parent.location.reload();
                    }
                })
            });
            return false;
        });
    });
</script>
</body>
</html>